// Creation History
// --------------------------------------------------------------
//	Company:   HTHK
//	NAME:	   DateFormatter.java
//	FUNCTION:  date object convertion
//	BY:
//	DATE:
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//  CR Log #: 1764    BY: Sun    DATE: 06/06/2005
//  ERROR:
//  FIX:   1) added new method
// --------------------------------------------------------------
//


// Copyright (c) 2002 HTHK
package com.ffpc.util;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Locale;
import java.util.Date;

/**
 * A Class class.
 * <P>
 * @author HTHK
 */
public class DateFormatter {
  // public  static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd",Locale.US);

  // Original
  private static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy",
      Locale.US);

  // End Original

  //  private static SimpleDateFormat sdf_n = new SimpleDateFormat("yyyyMMdd",Locale.US);
  private static SimpleDateFormat sdf_n = new SimpleDateFormat(
      "yyyyMMdd HH:mm:ss", Locale.US);

  public static String format(Timestamp time) {
    if (time == null)
      return null;
    return sdf.format( time);
  }

  public static String format_n(Timestamp time) {
    if (time == null)
      return null;
    return sdf_n.format( time);
  }

  public static Timestamp parse(String time) throws ParseException {
    if (time == null || time.trim().length() == 0)
      return null;

    return new Timestamp(sdf.parse(time).getTime());
  }

  public static Timestamp parse_n(String time) throws ParseException {
    if (time == null || time.trim().length() == 0)
      return null;
    return new Timestamp(sdf_n.parse(time).getTime());
  }

  public static String format_n(Date time) {
    if (time == null)
      return null;

    return sdf_n.format(time);
  }

  public static String format(Date time) {
    if (time == null)
      return null;
    return sdf.format(time);
  }

/* CR 1764 */
  public static String format(Timestamp time, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
    if (time == null)
      return null;
    return sdf.format(time);
  }
/* CR 1764 */
}
